package com.is.demo.generator.controller;


import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.is.demo.generator.entity.User;
import com.is.demo.generator.mapper.UserMapper;
import com.is.demo.generator.service.IUserService;
import com.is.demo.generator.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author will
 * @since 2020-07-06
 */
@Slf4j
@RestController
@RequestMapping(name = "testdemo1",value = "/generator/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping(path = "test")
    public List<User> test() {
        return userService.test();
    }

    @RequestMapping(path = "getname")
    public String getName(String id) {
        return userService.getName(id);
    }

    @RequestMapping(path = "savebatch")
    public boolean saveBatch(@RequestBody Collection<User> entityList) {
        return userService.saveBatch(entityList);
    }

    @RequestMapping(path = "testbody")
    public String saveBatch(@RequestBody Map<String, Object> map) {
        Console.log(map);

        return map.get("flag").toString();
    }

    @RequestMapping(path = "querybycondition")
    public List<User> queryByCondition(@RequestBody Map<String, Object> map) {
        return userService.queryByCondition(map);
    }

    @RequestMapping(path = "querypage")
    public Page<User> queryPage(long current, long size) {
        return userService.queryPage(current,size);
    }
}
